package perso.perso.converteur;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import perso.perso.view.admin.user.BeanUser;

import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;

public class BeanSchoolDateConverteur implements Converter {

	public boolean canConvert(Class clazz) {
		return clazz.equals(Date.class);
	}

	public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
	}

	public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			return sdf.parse(reader.getValue());
		} catch (ParseException e) {
			return null;
		}
	}

}
